package com.homegoods.designer.item;

import android.databinding.BindingAdapter;
import android.text.SpannableStringBuilder;

import com.alibaba.android.arouter.launcher.ARouter;
import com.hedgehog.ratingbar.RatingBar;
import com.homegoods.classify.model.Constant;
import com.homegoods.designer.R;
import com.homegoods.designer.model.DesignerModel;
import com.homegoods.designer.util.Utils;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseItem;

/**
 * @author QiQi
 * @ClassName: DesignerItem
 * @date 2018/9/15
 * @description
 */
public class DesignerItem extends BaseItem<DesignerModel> {
    public DesignerItem(DesignerModel data, MultiTypeAdapter adapter) {
        super(data);
        setOnClickListener(v -> ARouter.getInstance()
                .build(ARouterPath.PATH_DESIGNER_HOME)
                .withString("id", data.getSid())
                .navigation());
    }

    @BindingAdapter(value = {"star"})
    public static void setStar(RatingBar ratingBar, float code) {
        ratingBar.setStar(code);
    }

    public String getName() {
        return getData().getName();
    }


    public String getHeadUrl() {
        return Constant.SERVER_URL + getData().getBgimg();
    }

    /**
     * jingyan:机构经验    ['1年设计经验|0','2年设计经验|1','3年设计经验|2','4年设计经验|3','5年及5年以上设计经验|4']
     *
     * @return
     */
    public String getExp() {
        String exp = "";
        switch (getData().getJingyan()) {
            case 0:
                exp = "1年设计经验";
                break;
            case 1:
                exp = "2年设计经验";
                break;
            case 2:
                exp = "3年设计经验";
                break;
            case 3:
                exp = "4年设计经验";
                break;
            case 4:
                exp = "5年及5年以上设计经验";
                break;

        }
        return exp;
    }


    public String getType() {
        return getData().getType() == 0 ? "设计公司" : "设计师";
    }

    /**
     * fanwei:范围  [轻装|0,硬装|1,轻装+硬装|2]
     *
     * @return
     */
    public String getScope() {
        String scope = "";
        if (getData().getFanwei() == 0) {
            scope = "轻装";
        } else if (getData().getFanwei() == 1) {
            scope = "硬装";
        } else {
            scope = "轻装+硬装";
        }
        return scope;
    }


    public SpannableStringBuilder getPrice() {
        return Utils.getOffer(getData().getBaojia());
    }


    public int getLevel() {
        return getData().getLevel();
    }


    @Override
    public int getLayout() {
        return R.layout.designer_item_layout;
    }
}
